package utils
{
	import mx.collections.ArrayCollection;
	
	public class ArrayCollectionUtils
	{
		public static function findInCollection(c:ArrayCollection, findFunction:Function):Array
		{ 
			var matches : Array = c.source.filter( findFunction ); 
			return matches;
		}
		
		public static function findFunction(propertyName:String,propertyValue:*):Function
		{   
			return function( element : *, index : int, array : Array ) : Boolean   
			{    
				return element[propertyName] == propertyValue;   
			}
		}
		
		public static function copyArrayCollection(sourceArray:ArrayCollection):ArrayCollection
		{	
			var copy:ArrayCollection = new ArrayCollection();
			
			if(sourceArray != null && sourceArray.length > 0)
			{		
				for(var i:Number = 0; i<sourceArray.length; i++)
				{			
					copy.addItem(sourceArray.getItemAt(i));		
				}	
			}
			
			return copy;
		}
	}
}